const express = require("express");
const ejs = require("ejs");
const app = express();
const voteList = [
	{
		id:1,
		nm:"拯救嫌疑人",
		vote:0
	},
	{
		id:2,
		nm:"泰坦尼克号",
		vote:100
	},
	{
		id:3,
		nm:"小六壬",
		vote:200
	},
	{
		id:4,
		nm:"其实都没有",
		vote:300
	}
];
app.get("/",(req,res)=>{
	res.render("index.ejs",{
		voteList
	})
})

app.get("/vote/:id",(req,res)=>{
	// 接收id,id是获取投票信息的标识
	const {id} = req.params;
	// 根据标识找到投票信息
	const info = voteList.find(v=>v.id === id/1);
	// 票数加1
	info.vote++;
	// res.send("投票成功");
	res.redirect("/");
})

app.listen(80,()=>{
	console.log("success");
})